package svc

import (
	"platform/internal/config"
	"platform/internal/middleware"
	"platform/pkg/auth"
	"platform/pkg/pluginmgr"

	"github.com/zeromicro/go-zero/rest"
)

type ServiceContext struct {
	Config         config.Config
	Auth           *auth.AuthService
	PluginManager  *pluginmgr.PluginManager
	AuthMiddleware rest.Middleware
}

func NewServiceContext(c config.Config) *ServiceContext {
	authService := auth.NewAuthService(c.Auth.Secret, c.Auth.TokenDuration)
	pluginManager := pluginmgr.NewPluginManager()

	svcCtx := &ServiceContext{
		Config:        c,
		Auth:          authService,
		PluginManager: pluginManager,
	}

	// 初始化中间件
	svcCtx.AuthMiddleware = middleware.NewAuthMiddleware().Handle

	return svcCtx
}
